package caat.application.dao;

import java.sql.Connection;
import java.util.Collection;
import java.util.Vector;

import caat.application.entityobject.AdminEO;
import caat.framework.datamanager.AppDAO;
import caat.framework.exception.DAOException;

@SuppressWarnings("serial")
public class AdminDAO extends AppDAO {
	 private static String CLASS_NAME_DAO = "caat.application.dao.AdminDAO";
	 private static String CLASS_NAME_VO = "caat.application.entityobject.AdminEO";
	 private static String STRING_EMPTY="";
	 Connection conn=null;
		public AdminDAO(Connection conn) {
			super();
			this.conn = conn;
		}
	 /*
	  * @param: menh de WhereClause, vertor tham so
	  * @see : lay ra 1 ban ghi trong tblAdmin
	  * @Return AdminEO 
	  * */
	 @SuppressWarnings("rawtypes")
	public AdminEO getAdmin(String whereClause, Vector params) throws DAOException{
		 AdminEO adminEO = null;
		 try{
			 StringBuffer sbSQL = new StringBuffer();
			 sbSQL.append("select a.username,a.password from tblAdmin a ");
			 if(whereClause!=null && !STRING_EMPTY.equalsIgnoreCase(whereClause)){
				 sbSQL.append("where " + whereClause);
			 }
			 adminEO = (AdminEO)findByPK(sbSQL.toString(), params, CLASS_NAME_VO,conn);
		 }catch(Exception ex){
			 ex.printStackTrace();
			 throw new DAOException(CLASS_NAME_DAO + ".getAdmin(): " +
                     ex.getMessage(), ex);
		 }
		 return adminEO;
	 }
	@SuppressWarnings("rawtypes")
	public Collection getAllAdmin(String whereClause, Vector parameters) throws DAOException{
		 try {
			 StringBuffer sbSQL = new StringBuffer();
			 sbSQL.append("select a.username,a.password,a.address,a.phonenumber,a.sex from tblAdmin a ");
			 return executeSelectStatement(sbSQL.toString(), parameters, CLASS_NAME_VO, conn);
		} catch (Exception ex) {
			// TODO: handle exception
			ex.printStackTrace();
			throw new DAOException(CLASS_NAME_DAO + ".getAllAdmin(): " +
                    ex.getMessage(), ex);
		}		
	 }
}
